package adapter;

import java.util.ArrayList;
import java.util.List;

import com.activity.MainAppActivity;
import com.activity.R;

import entities.Category;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AdapterMainCategory extends ArrayAdapter<Category> {
	private Context context;
	private int resId;
	private List<Category> arrayList;

	public AdapterMainCategory(Context context, int resource,
			List<Category> listCategory) {
		super(context, resource, listCategory);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.resId = resource;
		this.arrayList = listCategory;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(resId, null);
		}
		ImageView image = (ImageView) convertView
				.findViewById(R.id.imageView_img);
		TextView txtName = (TextView) convertView
				.findViewById(R.id.textView_category);
		txtName.setTypeface(MainAppActivity.typeFaceFont);
		image.setImageBitmap(arrayList.get(position).getBitmap());
		if (MainAppActivity.localeCode.equalsIgnoreCase("vi"))
			txtName.setText(arrayList.get(position).getName());
		else
			txtName.setText(arrayList.get(position).getEngName());
		return convertView;
	}
}
